<template>
    <div>
      <h3>Tearsillusion/LowCode</h3>
      <p>包含导出和复制功能的低代码视图。</p>
  
      <!-- 可视化设计器 -->
      <div class="designer-section">
        <h4>可视化设计器</h4>
        <div class="design-area">
          <draggable v-model="components" @end="onDragEnd" item-key="name">
            <template #item="{ element, index }">
              <div class="component-item">
                {{ element.name }}
                <button @click="copyComponent(index)">复制</button>
              </div>
            </template>
          </draggable>
        </div>
      </div>
  
      <!-- 导出功能 -->
      <div class="export-section">
        <h4>导出功能</h4>
        <button @click="exportDesign">导出设计</button>
        <pre v-if="exportedData">{{ exportedData }}</pre>
      </div>
    </div>
  </template>
  
  <script setup>
  import { ref } from 'vue';
  import draggable from 'vuedraggable'; // 引入 vuedraggable 实现拖拽功能
  
  // 模拟组件数据
  const components = ref([
    { name: 'Header' },
    { name: 'Button' },
    { name: 'Form' }
  ]);
  
  // 模拟导出数据
  const exportedData = ref(null);
  
  // 复制组件
  const copyComponent = (index) => {
    const newComponent = { ...components.value[index] };
    components.value.splice(index + 1, 0, newComponent);
  };
  
  // 导出设计
  const exportDesign = () => {
    exportedData.value = JSON.stringify(components.value, null, 2);
  };
  
  // 拖拽结束时的处理函数
  const onDragEnd = () => {
    console.log('拖拽结束');
  };
  </script>
  
  <style scoped>
  .designer-section,
  .export-section {
    margin-bottom: 20px;
  }
  
  .design-area {
    border: 1px solid #ccc;
    padding: 10px;
    min-height: 100px;
  }
  
  .component-item {
    background-color: #f0f0f0;
    margin: 5px 0;
    padding: 5px;
    display: flex;
    justify-content: space-between;
    align-items: center;
  }
  
  button {
    padding: 5px 10px;
    cursor: pointer;
  }
  
  pre {
    background-color: #f9f9f9;
    padding: 10px;
    border: 1px solid #ddd;
    white-space: pre-wrap;
  }
  </style>